import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Debug App',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const TodoListPage(),
    );
  }
}

class TodoListPage extends StatefulWidget {
  const TodoListPage({super.key});

  @override
  State<TodoListPage> createState() => _TodoListPageState();
}

class _TodoListPageState extends State<TodoListPage> {
  // 模拟待办事项数据
  List<TodoItem> _todos = [
    TodoItem(
      id: '1',
      title: '完成项目报告',
      date: '2023-06-15',
      priority: '高',
      isCompleted: false,
      category: '工作',
    ),
    TodoItem(
      id: '2',
      title: '购买 groceries',
      date: '2023-06-12',
      priority: '中',
      isCompleted: true,
      category: '生活',
    ),
  ];

  // 当前选中的分类
  final String _selectedCategory = '全部';

  @override
  Widget build(BuildContext context) {
    final filteredTodos = _getFilteredTodos();

    return Scaffold(
      appBar: AppBar(
        title: const Text('我的待办'),
        centerTitle: true,
        elevation: 0,
      ),
      body: Padding(
        padding: const EdgeInsets.all(16.0),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            // 简单文本测试
            const Text('测试内容'),
            
            // 待办事项列表
            Expanded(
              child: ListView.builder(
                itemCount: filteredTodos.length,
                itemBuilder: (context, index) {
                  final todo = filteredTodos[index];
                  return _buildTodoItem(todo);
                },
              ),
            ),
          ],
        ),
      ),
    );
  }

  // 筛选待办事项
  List<TodoItem> _getFilteredTodos() {
    if (_selectedCategory == '全部') {
      return _todos;
    }
    return _todos.where((todo) => todo.category == _selectedCategory).toList();
  }

  // 构建待办事项项
  Widget _buildTodoItem(TodoItem todo) {
    return Container(
      margin: const EdgeInsets.only(bottom: 12),
      padding: const EdgeInsets.all(16),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(12),
        boxShadow: [
          BoxShadow(
              color: Colors.grey.withAlpha(25),
              spreadRadius: 2,
              blurRadius: 5,
              offset: const Offset(0, 2),
            ),
        ],
      ),
      child: Row(
        children: [
          // 复选框
          Checkbox(
            value: todo.isCompleted,
            onChanged: (value) {
              _toggleTodoStatus(todo.id);
            },
            activeColor: Colors.blue,
          ),
          const SizedBox(width: 12),

          // 待办信息
          Expanded(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  todo.title,
                  style: TextStyle(
                    fontSize: 16,
                    fontWeight: FontWeight.w500,
                    decoration: todo.isCompleted
                        ? TextDecoration.lineThrough
                        : TextDecoration.none,
                    color: todo.isCompleted ? Colors.grey : Colors.black,
                  ),
                ),
                const SizedBox(height: 4),
                Text(
                  todo.date,
                  style: const TextStyle(
                    fontSize: 12,
                    color: Colors.grey,
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }

  // 切换待办事项完成状态
  void _toggleTodoStatus(String id) {
    setState(() {
      _todos = _todos.map((todo) {
        if (todo.id == id) {
          return TodoItem(
            id: todo.id,
            title: todo.title,
            date: todo.date,
            priority: todo.priority,
            isCompleted: !todo.isCompleted,
            category: todo.category,
          );
        }
        return todo;
      }).toList();
    });
  }
}

// 待办事项数据模型
class TodoItem {
  final String id;
  final String title;
  final String date;
  final String priority;
  final bool isCompleted;
  final String category;

  TodoItem({
    required this.id,
    required this.title,
    required this.date,
    required this.priority,
    required this.isCompleted,
    required this.category,
  });
}